#include "header.h"
int so(char s[])
{  
  int i, j; 
  int numget=0; 
  for (i = 0; s[i] != 0; i++) 
    while (((s[i]>'9') || (s[i]<'0')) && (s[i] != 0)) 
      for (j = i; j <=strlen(s); j++) 
        s[j] = s[j+1]; 
  return numget; 
}  
void cau3()
{
     int T,n,i,axis,val=0;
     int k,l;
     char action[100];
     char *s;
     s=(char *)malloc((20)*sizeof(char));
     scanf("%d",&T);
     while(T)
     {
             axis=0;
             T--;
             scanf("%d",&n);
             for(i=1;i<=n;i++)
             {
                             
                              fflush(stdin);
                              gets(s);
                              if(*s=='L')
                              {
                                         axis--;
                                         action[i]='L';
                                         }
                              else if(*s=='R')
                                   {
                                              axis++;
                                              action[i]='R';
                                             }
                                   else
                                   {
                                       val=so(s);
                                 
                                       for(k=1;k<i;k++)
                                       if(val==k)
                                       {
                                                 if(action[k]=='L')
                                                 {
                                                                   axis--;
                                                                   action[i]=action[k];
                                                                   }
                                                 else
                                                 {
                                                                   axis++;
                                                                   action[i]=action[k];
                                                                   }
                                                                   }
                                   
                                                                   }
                                        
                                        }
              printf("%d",axis) ;                         
             }
             
}
